home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 October / macformat-108.iso / Shareware / Math scientific / PsyScript / libraries / BestPest.lib / BestPest.lib.rsrc / TEXT_2000_Source Text.txt < prev    next >
Encoding:
Text File  |  2001-06-21  |  1.9 KB  |  72 lines

  1. property refreshInterval : 12.5
  2. property maxDuration : 200
  3. property range : 0
  4. property maxTrials : 60
  5.  
  6. property m : 0 --stimulus value is m
  7. property r : 0 --observer response is r
  8.  
  9. property prob : {}
  10. property plgit : {}
  11. property mlgit : {}
  12.  
  13. set range to maxDuration div refreshInterval
  14. set STD to range / 5
  15.  
  16.  
  17. repeat with i from 1 to 2 * range -- + 1?
  18.     set end of prob to 0 --initialize prob array to 0
  19.     set lgit to 0.5 + 0.5 / (1 + (exponential of ((range - 1) / STD)))
  20.     set end of plgit to natural logarithm of (lgit)
  21.     set end of mlgit to natural logarithm of (1 - lgit)
  22. end repeat
  23.  
  24. set m to 1 -- set m to range
  25. set r to -1 -- set r to 1
  26. set m to my threshold(r)
  27. set m to 1 -- set m to range
  28. set r to 1 -- set r to -1
  29.  
  30. --main
  31. repeat with n from 1 to maxTrials
  32.     my threshold(r)
  33.     display dialog ("stimulus presented at " & m) default answer r
  34.     set r to text returned of result
  35. end repeat
  36.  
  37. to threshold(response)
  38.     --p1 points to the maximum value of the probability array
  39.     --p2  this is used if teh prob array has a flat peak at max
  40.     --In this case the next value is delivered at the average of this flat region (p1+p2)/2    
  41.     --update probabilities based on whether the response was correct
  42.     set max to -10000
  43.     if r = 1 then
  44.         repeat with i from 1 to range
  45.             set itemI to (a reference to item i of prob)
  46.             set itemI to (itemI + (item (range + m - i) of plgit))
  47.             --set p1 to  max value of array
  48.             if (itemI > max) then
  49.                 set max to contents of itemI
  50.                 set p1 to i
  51.                 set p2 to i
  52.             else if (itemI = max) then
  53.                 set p2 to i
  54.             end if
  55.         end repeat
  56.     else --error
  57.         repeat with i from 1 to range
  58.             set itemI to (a reference to item i of prob)
  59.             set itemI to (itemI + (item (range + m - i) of mlgit))
  60.             --set p1 to  max value of array
  61.             if (itemI > max) then
  62.                 set max to contents of itemI
  63.                 set p1 to i
  64.                 set p2 to i
  65.             else if (itemI = max) then
  66.                 set p2 to i
  67.             end if
  68.         end repeat
  69.     end if
  70.     set m to round ((p1 + p2) / 2) --update the next test value    
  71. end threshold
  72.